//
//  JKTagCell.m
//  JackToolsBox
//
//  Created by Jack Xue on 2019/12/10.
//  Copyright © 2019 Jack Xue. All rights reserved.
//

#import "JKTagPart.h"

@implementation JKTagPart
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.textAlignment = NSTextAlignmentCenter;
        _contentView = [[UIView alloc]initWithFrame:CGRectZero];
        [self addSubview:_contentView];
        
        _enableBorder = YES;
    }
    return self;
}
- (void)setInfoString:(NSString *)infoString{
    _infoString = infoString;
    self.text = _infoString;
    [self resize];
}

-(void)setFontSize:(CGFloat)fontSize{
    _fontSize = fontSize;
    self.font = [UIFont systemFontOfSize:_fontSize];
    [self resize];
}

-(void)resize{
    CGSize newSize = [self sizeThatFits:CGSizeMake(MAXFLOAT, 0)];
    newSize.width += 10;
    newSize.height += 5;
    CGRect newRect = self.frame;
    newRect.size.height = newSize.height;
    newRect.size.width = newSize.width;
    self.frame = newRect;
}

-(void)layoutSubviews{
    [super layoutSubviews];
    self.contentView.frame = self.bounds;
}

-(void)drawRect:(CGRect)rect{
    [super drawRect:rect];
    
    if (_enableBorder) {
        //绘制外边框
        UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(JK_LINE_WIDTH, JK_LINE_WIDTH, rect.size.width-JK_LINE_WIDTH*2, rect.size.height-JK_LINE_WIDTH*2) cornerRadius:4];
        path.lineWidth = JK_LINE_WIDTH;
        [self.forgroundColor setStroke];
        [path stroke];
    }
}


-(UIColor *)forgroundColor{
    if (!_forgroundColor) {
        _forgroundColor = [UIColor blackColor];
    }
    return _forgroundColor;
}


@end
